//
//  NSProcessInfoTests.m
//  iOS Sample Code
//
//  Created by lei yu on 11-12-9.
//  Copyright (c) 2011年 lancet. All rights reserved.
//

#import "NSProcessInfoTests.h"

@implementation NSProcessInfoTests

// All code under test must be linked into the Unit Test bundle

/*
 
 Method Description
 +(NSProcessInfo *) processInfo Returns information about the current process
 –(NSArray *) arguments Returns the arguments to the current process as an array of NSString objects
 –(NSDictionary *) environment Returns a dictionary of variable/value pairs representing the current environment variables (such as PATH and HOME) and their values
 –(int) processIdentifier Returns the process identifier, which is a unique number assigned by the operating system to identify each running process
 –(NSString *) processName Returns the name of the current executing process
 –(NSString *) Returns a different unique string each time it is globallyUniqueString invoked. This could be used for generating unique temporary filenames (see Exercise 5)
 –(NSString *) hostName Returns the name of the host system (returns Steve-Kochans-Computer.local on my Mac OS X system)
 –(NSUInteger) operatingSystem Returns a number indicating the operating system (returns the value 5 on my Mac)
 –(NSString *) operatingSystemName Returns the name of the operating system (returns  the constant NSMACHOperatingSystem on my Mac, where the possible return values are defined in NSProcessInfo.h)
 –(NSString *) operatingSystemVersionString Returns the current version of the operating system  (returns Version 10.6.7 (Build 10J869) on my Mac OS X system)
 –(void) setProcessName: (NSString *) name Sets the name of the current process to name. Should be used with caution because some assumptions can be made about the name of your process (for example, by the user default settings)
 */

-(void)testNSProcessInfo{
    
    
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSFileManager *fm;
    NSString *source, *dest;
    BOOL isDir;
    NSProcessInfo *proc = [NSProcessInfo processInfo];
    NSArray *args = [proc arguments];
     
    
    
     
    fm = [NSFileManager defaultManager];
    // Check for two arguments on the command line
    if ([args count] != 3) {
        NSLog (@"Usage: %@ src dest", [proc processName]);
     }
    source = [args objectAtIndex: 1]; 
    dest = [args objectAtIndex: 2];
    // Make sure the source file can be read
    if ([fm isReadableFileAtPath: source] == NO) {
        NSLog (@"Can't read %@", source);
        return ;
    }
    // See if the destination file is a directory
    // if it is, add the source to the end of the destination
    [fm fileExistsAtPath: dest isDirectory: &isDir];
    if (isDir == YES)
        dest = [dest stringByAppendingPathComponent:[source lastPathComponent]];
    // Remove the destination file if it already exists 
    [fm removeItemAtPath: dest error: NULL];
    // Okay, time to perform the copy
    
    if ([fm copyItemAtPath: source toPath: dest error: NULL] == NO) { 
        NSLog (@"Copy failed!");
        return ;
    }
    NSLog (@"Copy of %@ to %@ succeeded!", source, dest);
    [pool drain];
}


@end
